<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;

$(document).ready(function() {
listselectors();
});

function addnpc_unit() {
	var addnpc_unitUrl = "/npc_unit/add/";
	var nameValue = $("#name").val();
	if(!checkString("名字",nameValue,false)) {
		return;
	}
	var nameParam = "name=" + xparseString(nameValue);
		
	var descValue = $("#desc").val();
	if(!checkString("描述",descValue,false)) {
		return;
	}
	var descParam = "desc=" + xparseString(descValue);
		
	var levelValue = $("#level").val();
	if(!checkInteger("等级",levelValue,false)) {
		return;
	}
	var levelParam = "level=" + xparseInt(levelValue);
		
	var careerValue = $("#career").val();
	
	var careerParam = "career=" + careerValue;
		
	var genderValue = $("#gender").val();
	
	var genderParam = "gender=" + genderValue;
		
	var npcIdValue = $("#npcId").val();
	
	var npcIdParam = "npcId=" + npcIdValue;
		
	var idxValue = $("#idx").val();
	if(!checkInteger("排列顺序",idxValue,false)) {
		return;
	}
	var idxParam = "idx=" + xparseInt(idxValue);
		
	var posValue = $("#pos").val();
	if(!checkInteger("位置",posValue,false)) {
		return;
	}
	var posParam = "pos=" + xparseInt(posValue);
		
	var hpValue = $("#hp").val();
	if(!checkInteger("血量",hpValue,false)) {
		return;
	}
	var hpParam = "hp=" + xparseInt(hpValue);
		
	var attackIdValue = $("#attackId").val();
	if(!checkInteger("攻击顺序",attackIdValue,false)) {
		return;
	}
	var attackIdParam = "attackId=" + xparseInt(attackIdValue);
		
	var physicalatkValue = $("#physicalatk").val();
	if(!checkInteger("物理攻击力",physicalatkValue,false)) {
		return;
	}
	var physicalatkParam = "physicalatk=" + xparseInt(physicalatkValue);
		
	var physicaldefValue = $("#physicaldef").val();
	if(!checkInteger("物理防御力",physicaldefValue,false)) {
		return;
	}
	var physicaldefParam = "physicaldef=" + xparseInt(physicaldefValue);
		
	var magicatkValue = $("#magicatk").val();
	if(!checkInteger("魔法攻击力",magicatkValue,false)) {
		return;
	}
	var magicatkParam = "magicatk=" + xparseInt(magicatkValue);
		
	var magicdefValue = $("#magicdef").val();
	if(!checkInteger("魔法防御力",magicdefValue,false)) {
		return;
	}
	var magicdefParam = "magicdef=" + xparseInt(magicdefValue);
		
	var furyAttackRateValue = $("#furyAttackRate").val();
	if(!checkInteger("怒气攻击速率",furyAttackRateValue,false)) {
		return;
	}
	var furyAttackRateParam = "furyAttackRate=" + xparseInt(furyAttackRateValue);
		
	var hardAttackRateValue = $("#hardAttackRate").val();
	if(!checkInteger("重击攻击速率",hardAttackRateValue,false)) {
		return;
	}
	var hardAttackRateParam = "hardAttackRate=" + xparseInt(hardAttackRateValue);
		
	var hurtIncValueValue = $("#hurtIncValue").val();
	if(!checkInteger("伤害增加值",hurtIncValueValue,false)) {
		return;
	}
	var hurtIncValueParam = "hurtIncValue=" + xparseInt(hurtIncValueValue);
		
	var hurtDecValueValue = $("#hurtDecValue").val();
	if(!checkInteger("伤害减少值",hurtDecValueValue,false)) {
		return;
	}
	var hurtDecValueParam = "hurtDecValue=" + xparseInt(hurtDecValueValue);
		
	var hurtIncPercentValue = $("#hurtIncPercent").val();
	if(!checkInteger("伤害增加百分比",hurtIncPercentValue,false)) {
		return;
	}
	var hurtIncPercentParam = "hurtIncPercent=" + xparseInt(hurtIncPercentValue);
		
	var hurtDecPercentValue = $("#hurtDecPercent").val();
	if(!checkInteger("伤害减少百分比",hurtDecPercentValue,false)) {
		return;
	}
	var hurtDecPercentParam = "hurtDecPercent=" + xparseInt(hurtDecPercentValue);
		
	var skillsValue = $("#skills").val();
	if(!checkString("技能列表",skillsValue,false)) {
		return;
	}
	var skillsParam = "skills=" + xparseString(skillsValue);
		
	var equipmentValue = $("#equipment").val();
	if(!checkString("装备列表",equipmentValue,false)) {
		return;
	}
	var equipmentParam = "equipment=" + xparseString(equipmentValue);
		
	var styleValue = $("#style").val();
	if(!checkString("头饰列表",styleValue,false)) {
		return;
	}
	var styleParam = "style=" + xparseString(styleValue);
		
	var npcunitresValue = $("#npcunitres").val();
	
	var npcunitresParam = "npcunitres=" + npcunitresValue;
			
	$.ajax({
		   type: "POST",
		   url: addnpc_unitUrl,
		   data:   nameParam +'&'+ descParam +'&'+ levelParam +'&'+ careerParam +'&'+ genderParam +'&'+ npcIdParam +'&'+ idxParam +'&'+ posParam +'&'+ hpParam +'&'+ attackIdParam +'&'+ physicalatkParam +'&'+ physicaldefParam +'&'+ magicatkParam +'&'+ magicdefParam +'&'+ furyAttackRateParam +'&'+ hardAttackRateParam +'&'+ hurtIncValueParam +'&'+ hurtDecValueParam +'&'+ hurtIncPercentParam +'&'+ hurtDecPercentParam +'&'+ skillsParam +'&'+ equipmentParam +'&'+ styleParam +'&'+ npcunitresParam ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			       window.returnValue=1;
			       beforeWindowClose();
				   window.close();
			   }else {
				  errDialog(data.message);
			   }
		   }
	});
}

function listselectors() {
var getNPCSelectorUrl = "/special/NPC/getList/";
$.ajax({
		   type: "GET",
		   url: getNPCSelectorUrl,
		   data: "",
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   selectnpcId(s2json(data.result));
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

function selectnpcId(options) {
	var optionHTML = "";
	for(var i in options) {
		optionHTML = optionHTML + "<option value='"+ options[i][0] +"'>" + options[i][1] + "</option>\n";
	}
	$("#npcId").html(optionHTML);
}

function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("npc_unit",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/npc_unit/add" method="post">
		<table>
			<tbody>				
					<tr>					<td>
						<label for="name" id="lbl_name">名字</label>
													<input type="text" id="name" name="name" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="desc" id="lbl_desc">描述</label>
													<input type="text" id="desc" name="desc" /><span class="tips">[文字]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="level" id="lbl_level">等级</label>
													<input type="text" id="level" name="level" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="career" id="lbl_career">职业要求</label>
																				<select id="career" name="career">
								
									<option value="0">职业不限</option>
								
									<option value="1">武将</option>
								
									<option value="2">文官</option>
															</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="gender" id="lbl_gender">性别要求</label>
																				<select id="gender" name="gender">
								
									<option value="0">性别不限</option>
								
									<option value="1">男</option>
								
									<option value="2">女</option>
															</select>
											</td>
									
										<td>
						<label for="npcId" id="lbl_npcId">所属NPC</label>
													<select id="npcId" name="npcId">
							</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="idx" id="lbl_idx">排列顺序</label>
													<input type="text" id="idx" name="idx" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="pos" id="lbl_pos">位置</label>
													<input type="text" id="pos" name="pos" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="hp" id="lbl_hp">血量</label>
													<input type="text" id="hp" name="hp" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="attackId" id="lbl_attackId">攻击顺序</label>
													<input type="text" id="attackId" name="attackId" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="physicalatk" id="lbl_physicalatk">物理攻击力</label>
													<input type="text" id="physicalatk" name="physicalatk" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="physicaldef" id="lbl_physicaldef">物理防御力</label>
													<input type="text" id="physicaldef" name="physicaldef" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="magicatk" id="lbl_magicatk">魔法攻击力</label>
													<input type="text" id="magicatk" name="magicatk" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="magicdef" id="lbl_magicdef">魔法防御力</label>
													<input type="text" id="magicdef" name="magicdef" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="furyAttackRate" id="lbl_furyAttackRate">怒气攻击速率</label>
													<input type="text" id="furyAttackRate" name="furyAttackRate" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="hardAttackRate" id="lbl_hardAttackRate">重击攻击速率</label>
													<input type="text" id="hardAttackRate" name="hardAttackRate" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="hurtIncValue" id="lbl_hurtIncValue">伤害增加值</label>
													<input type="text" id="hurtIncValue" name="hurtIncValue" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="hurtDecValue" id="lbl_hurtDecValue">伤害减少值</label>
													<input type="text" id="hurtDecValue" name="hurtDecValue" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="hurtIncPercent" id="lbl_hurtIncPercent">伤害增加百分比</label>
													<input type="text" id="hurtIncPercent" name="hurtIncPercent" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="hurtDecPercent" id="lbl_hurtDecPercent">伤害减少百分比</label>
													<input type="text" id="hurtDecPercent" name="hurtDecPercent" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="skills" id="lbl_skills">技能列表</label>
													<input type="text" id="skills" name="skills" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="equipment" id="lbl_equipment">装备列表</label>
													<input type="text" id="equipment" name="equipment" /><span class="tips">[文字]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="style" id="lbl_style">头饰列表</label>
													<input type="text" id="style" name="style" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="npcunitres" id="lbl_npcunitres">npc英雄资源</label>
													<input type="text" id="npcunitres" name="npcunitres" disabled/>
							<input type="button" value="..." onclick="openResource('npcunitres','')"/><span class="tips">[资源]</span>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="addnpc_unit()" value="添加"/>
	</form>
	</div>
</body>